<?php
	require('webservices.php');
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
	<head>
		<link rel="stylesheet" type="text/css" href="css/template.css">
		<link rel="stylesheet" type="text/css" href="css/smoothness/jquery-ui-1.10.0.custom.css" />
		<script type="text/javascript" src="JQuery/jquery-1.9.0.min.js"></script>
		<script type="text/javascript" src="JQuery/jquery-ui-1.10.0.custom.js"></script>	
		<script type="text/javascript" src="JS/SubmitTest.js"></script>	
		<title>Submit Test</title>
	</head> 
	<body>
	<?php
		require('webservices.php');

        $TestRecordID = $_POST["RecordID"];
        unset($_POST["RecordID"]);
	
        $Pledge = $_POST["PledgeName"];
        unset($_POST["PledgeName"]);
		$TestRecordID = $_POST["RecordID"];
		unset($_POST["RecordID"]);
		
		$Pledge = $_POST["PledgeName"];
		unset($_POST["PledgeName"]);

		
		Submit_test($TestRecordID, $Pledge);

        foreach($_POST as $question => $answer)
        {
            Answer_test_question($answer, $question, $TestRecordID);
        }
	
        Auto_grade_answer($TestRecordID);
        echo "completed";
        header("Location: main.php");
		foreach($_POST as $question => $answer)
		{
			if(is_array($answer))
			{
				foreach($answer as $a)
				{
					Answer_test_question($a, $question, $TestRecordID);
				}
			}
			else
			{
				Answer_test_question($answer, $question, $TestRecordID);
			}
			
			unset($_POST[$question]);
		}
		
		echo '<script type="text/javascript">';
		echo 'SubmitComplete();';
		echo '</script>';

?>
	?>
	<div id="ConfirmDialog" title="Test Completed" style="display:none;">
		<img src="images/Process-success.png" id="DialogIcon" /><span id="DialogMessage">Your test has been submitted to the instructor. You will redirected back to the home page</span>
	</div>
	</body>
			
</html>